<template>
  <view class="goods-list">
    <view class="goods-item">
      <view class="goods-item-left">
        <radio value="" v-if="showRadio" @click="radioClickHandler" :checked="goods.goods_state" color="#FF4536" />
        <text></text>
        <image :src="goods.goods_small_logo||defaultPic" mode=""></image>
      </view>
      <view class="goods-item-right">
        <view class="goods-name">
          {{goods.goods_name}}
        </view>
       <view class="goods-info-box">
         <view class="goods-price">
           ￥{{goods.goods_price | tofixed}}
         </view>
         <uni-number-box @change="numChangeHandler" :min="1" :value="goods.goods_count" v-if="showNumberBox"></uni-number-box>
       </view>
       
      </view>
    </view>
  </view>
</template>

<script>

  export default {
    name: "my-goods",
    data() {
      return {
        defaultPic: 'https://img3.doubanio.com/f/movie/8dd0c794499fe925ae2ae89ee30cd225750457b4/pics/movie/celebrity-default-medium.png', //默认图片 如果图片是空白就显示默认图片
      };
    },
    props: {
      goods: {
        type: Object,
        default: {}
      },
      showRadio: {
        type: Boolean,
        default: false
      },
      showNumberBox: {
        type: Boolean,
        default: false
      }
    },
    filters: {
      tofixed(num) {
        return Number(num).toFixed(2)
      }
    },
    methods: {
      // 选择商品
      radioClickHandler() {
        this.$emit('radio-change', {
          // 商品的 Id
          goods_id: this.goods.goods_id,
          // 商品最新的勾选状态
          goods_state: (!this.goods.goods_state)
        })
      },
      // 添加数量
      numChangeHandler(val){
        this.$emit('num-change',{
          goods_id:this.goods.goods_id,
          goods_count:+val
        })
      }
    }
  }
</script>

<style lang="scss">
  .goods-list {
    display: flex;
    flex-direction: column;

    .goods-item {
      display: flex;
      margin: 20rpx 0;

      .goods-item-left {
        display: flex;
        align-items: center;
        justify-content: space-between;

        padding: 10rpx;

        radio {
          padding: 0 20rpx;
        }

        image {
          width: 100px;
          height: 100px;
          display: block;
        }
      }

      .goods-item-right {
        margin-left: 20rpx;
        display: flex;
        flex-direction: column;
        justify-content: space-around;

        .goods-name {
          font-size: 24rpx;
        }
        .goods-info-box{
          display: flex;
          justify-content: space-between;
          align-items: center;
          .goods-price {
            color: #FF4536;
          }
        }

      
      }
    }
  }
</style>
